package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowUserguideType;
import cn.stylefeng.guns.modular.manager.mapper.FlowUserguideTypeMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowUserguideTypeParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowUserguideTypeResult;
import  cn.stylefeng.guns.modular.manager.service.FlowUserguideTypeService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 用户指南类型 服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-07
 */
@Service
public class FlowUserguideTypeServiceImpl extends ServiceImpl<FlowUserguideTypeMapper, FlowUserguideType> implements FlowUserguideTypeService {

    @Override
    public void add(FlowUserguideTypeParam param){
        FlowUserguideType entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowUserguideTypeParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowUserguideTypeParam param){
        FlowUserguideType oldEntity = getOldEntity(param);
        FlowUserguideType newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowUserguideTypeResult findBySpec(FlowUserguideTypeParam param){
        return null;
    }

    @Override
    public List<FlowUserguideTypeResult> findListBySpec(FlowUserguideTypeParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowUserguideTypeParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowUserguideTypeParam param){
        return param.getUserguideTypeId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowUserguideType getOldEntity(FlowUserguideTypeParam param) {
        return this.getById(getKey(param));
    }

    private FlowUserguideType getEntity(FlowUserguideTypeParam param) {
        FlowUserguideType entity = new FlowUserguideType();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
